<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '菜单管理';
$this->params['breadcrumbs'][] = ['label' => '系统管理', 'template' => "<li><a>{link}</a></li>\n"];
$this->params['breadcrumbs'][] = $this->title;
$this->params['plugins'][] = 'footable';
?>

<div class="ibox-content m-b-sm border-bottom">
    <?= Html::a('新增', ['create'], ['class' => 'btn btn-success']) ?>
    <?= Html::a('回收站', ['recycle'], ['class' => 'btn btn-default']) ?>
</div>

<?php Pjax::begin(); ?>
<div class="ibox">
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'options' => [
            'class' => 'ibox-content',
        ],
        'tableOptions' => [
            'class' => 'footable table table-stripped toggle-arrow-tiny',
        ],
        'columns' => [
            [
                'class' => 'yii\grid\SerialColumn',
                'headerOptions' => [
                    'data-hide' => "phone",
                ],
            ],

            'id',
            [
                'attribute' => 'parent_id',
                'value' => function($data){
                    return $data->parent ? $data->parent->name : '';
                },
            ],
            'name',
            'status',

            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '<div class="btn-group">{view}{update}{remove}</div>',
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                        $options = [
                            'title' => '查看',
                            'class' => 'btn-white btn btn-xs',
                        ];
                        return Html::a('查看', $url, $options);
                    },
                    'update' => function ($url, $model, $key) {
                        $options = [
                            'title' => '编辑',
                            'class' => 'btn-white btn btn-xs',
                        ];
                        return Html::a('编辑', $url, $options);
                    },
                    'remove' => function ($url, $model, $key) {
                        $options = [
                            'title' => '移除',
                            'aria-label' => '移除',
                            'data-confirm' => '确定要移除这个菜单吗？',
                            'data-method' => 'post',
                            'data-pjax' => '1',
                            'class' => 'btn-white btn btn-xs',
                        ];
                        return Html::a('移除', $url, $options);
                    }
                ]
            ],
        ],
    ]); ?>
</div>
<?php Pjax::end(); ?>

<?php

$js = <<<JS
    $('.footable').footable();
JS;

$this->registerJs($js);

